<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>

<%@include file="/common/head.jsp" %>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <form role="form" class="form-inline" id="query-form" method="post"
                          action="${ctx }/admin/agent/list">
                        <!-- 查询开始 -->
                        <div class="form-group">
                            <input type="text" id="query-name" name="orgNameOrManager" value="${query.orgNameOrManager}"
                                   class="form-control input-sm" placeholder="查询代理商名称/负责人">

                        </div>
                        <div class="form-group">
                            <label for="query-status" class="sr-only2">状态</label>
                            <select name="status" id="query-status" class="form-control">
                                <option value="" <c:if test="${query.status == null}">selected</c:if>>全部</option>
                                <option value="0" <c:if test="${query.status == 0}">selected</c:if>>禁用</option>
                                <option value="1" <c:if test="${query.status == 1}">selected</c:if>>启用</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <button class="btn btn-primary btn-sm" type="submit"><i class="fa fa-search"></i>&nbsp;查询
                            </button>
                        </div>
                        <!-- 查询结束 -->
                    </form>

                    <div>
                        <p>
                            <button type="button" class="btn btn-sm btn-outline btn-primary" onclick="add()"><i
                                    class="fa fa-plus"></i> 新增
                            </button>
                        </p>
                    </div>
                    <table id="table" data-toggle="table" data-striped="true" data-click-to-select="true"
                           data-mobile-responsive="true">
                        <thead>
                        <tr>
                            <th data-field="id" data-visible="false">ID</th>
                            <%--<th data-field="user">对应用户</th>--%>
                            <th data-field="status">状态</th>
                            <th data-field="orgName">机构名称</th>
                            <th data-field="manager">负责人</th>
                            <th data-field="mobile">联系方式</th>
                            <th data-field="customers">医生总量</th>
                            <th data-field="operation">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${list }" var="n" varStatus="idx">
                            <tr data-index="${idx.index }" data-id="${n.id }">
                                <td style="">${n.id }</td>
                                    <%--<td style="">${n.user.id}</td>--%>
                                <td>${enum:list('AgentStatus', n.status)}</td>
                                <td style="">${n.orgName }</td>
                                <td style="">${n.manager }</td>
                                <td style="">${n.mobile }</td>
                                <td style="">${n.customers }</td>
                                <td style="">
                                    <c:if test="${n.status == 0}">
                                        <a href="javascript: void(0);" onclick="updateStatus(${n.id}, 1)">启用</a>&nbsp;&nbsp;
                                    </c:if>
                                    <c:if test="${n.status == 1}">
                                        <a href="javascript: void(0);" onclick="updateStatus(${n.id}, 0)">禁用</a>&nbsp;&nbsp;
                                    </c:if>
                                    <a href="javascript: void(0);" onclick="edit(${n.id})">编辑</a>&nbsp;&nbsp;
                                    <a href="javascript: void(0);" onclick="detail(${n.id})">查看明细</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                    <%@include file="/common/page.jsp" %>
                </div>
            </div>
        </div>
    </div>
</div>

<%@include file="/common/foot.jsp" %>
<script>
    function add() {
        k.layer.add("${ctx}/admin/agent/detail", null, {title: '新增代理商'});
    }

    function edit(id) {
        layer.open({
            title: '编辑信息',
            type: 2,
            skin: 'layui-layer-rim', //加上边框
            area: [layer_default_width, layer_default_height], //宽高
            content: "${ctx}/admin/agent/detail?id=" + id,
            btn: ['确定', '取消'],
            yes: function(index, layero){ //或者使用btn1
                var detailForm = layer.getChildFrame('form', index);
                var iframeWin = window[layero.find('iframe')[0]['name']];
                if(iframeWin.validateInput()){
                    detailForm.ajaxSubmit({
                        success: function(data) {
                                if (isSuccess(data)) {
                                    layer.close(index);
                                    reload();
                                }
                        }
                    });
                }
            }, cancel: function(index){ //或者使用btn2
                //按钮【按钮二】的回调
            },
            end: function() {
                // alert('end')
            }
        });
    }

    function detail(id) {
        k.layer.showDetail("${ctx}/admin/agent/checkDetail?id="+id);
    }

    function updateStatus(id, status) {
        k.layer.updateStatus('${ctx}/admin/agent/deleteOrActivate', id, status);
    }

    var page = "${page.page}";

    function reload() {
        page_submit(page);
    }
    paging('pagination', ${page.totalPages}, ${page.page});

</script>
</body>
</html>